﻿using jlynet.core.Library;
using jlynet.core.notebook.model;
using jlynet.core.notebook.util;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Windows.Forms;

namespace jlynet.core.notebook.myform
{

    public partial class MiniPasswordBoxForm : Form
    {
        private NotifyIcon notifyIcon1 = new NotifyIcon();
        private ContextMenu notifyiconMnu;

        //用户密码
        public static string User_Password { get; set; }

        public MiniPasswordBoxForm()
        {
            InitializeComponent();

            //this.MinimizeBox = false;  //去掉最小化
            this.MaximizeBox = false;  //去掉最大化
            //设置在窗体标题栏上显示的图标
            this.Icon = UserResource.preferences_desktop_user_password_128px_ico;
            this.notifyIcon1.Icon = UserResource.preferences_desktop_user_password_128px_ico;

            //在双击控件时发生
            this.notifyIcon1.DoubleClick += (s, e) =>
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.Show();
                    this.WindowState = FormWindowState.Normal;//还原窗体显示
                    this.Activate();//激活窗体并给予它焦点 
                    this.ShowInTaskbar = true;//任务栏区显示图标
                    this.notifyIcon1.Visible = false;//托盘区图标隐藏 
                }
            };

            //当窗体大小改变时
            this.SizeChanged += (s, e) =>
            {
                if (this.WindowState == FormWindowState.Minimized)
                { //判断是否最小化
                    this.Hide();
                    this.WindowState = FormWindowState.Minimized;
                    this.ShowInTaskbar = false;//false 在任务栏中不显示图标 | true 显示图标
                    this.notifyIcon1.Visible = true;//图标显示在托盘区
                    this.Initializenotifyicon();
                }
            };

            TreeViewHelper.setTreeView("treeView_menuList", this).SelectData();
            //treeViewHelper.treeViewClickSelectListViewData(this.treeView_menuList, this.listView_entryData, this);
            createListViewRightMenu(this.listView_entryData, this.treeView_menuList, this);
            //listViewHelper.CreateListHeader(this.listView_entryData);
            //listViewHelper.ListViewData(this.listView_entryData);

            //当窗体关闭时保存窗体坐标
            this.FormClosing += (s, e) =>
            {
                INIHelper ini = new INIHelper(INIFileInitialization.INIPath);
                ini.IniWriteValue("LOC", "x", this.Location.X.ToString());
                ini.IniWriteValue("LOC ", "y", this.Location.Y.ToString());
            };

            //当窗体启动时，读取INI文件的值并赋值给窗体
            this.Load += (s, e) =>
            {

                INIHelper ini = new INIHelper(INIFileInitialization.INIPath);

                Point p = new Point();

                //判断返回值，避免第一次运行时为空出错  
                if ((ini.IniReadValue("LOC", "x") != "") && (ini.IniReadValue("LOC", "y") != ""))
                {
                    p.X = int.Parse(ini.IniReadValue("LOC", "x"));
                    p.Y = int.Parse(ini.IniReadValue("LOC", "y"));

                    // int.Parse将字符串转换为int  
                    this.Location = p;
                }
            };

            //点击treeView节点执行数据查询展示到ListView
            treeViewClickSelectListViewData(this.treeView_menuList, this.listView_entryData,this);

        }

        /// <summary>
        /// 点击treeView节点执行数据查询展示到ListView
        /// </summary>
        /// <param name="treeView"></param>
        /// <param name="listView"></param>
        public void treeViewClickSelectListViewData(TreeView treeView_menuList, ListView listView_entryData, Form form)
        {
            try
            {
                //reeview生成以后就支持单击节点修改。
                //treeView.LabelEdit = true;

                //右键菜单
                ContextMenuStrip contextMenuStrip1 = new ContextMenuStrip();
                //contextMenuStrip1.Items.Clear();
                contextMenuStrip1.Items.Add("添加目录");
                contextMenuStrip1.Items[0].Image = UserResource.folder;
                contextMenuStrip1.Items[0].TextAlign = ContentAlignment.MiddleRight;
                contextMenuStrip1.Items[0].DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                contextMenuStrip1.Items[0].ImageAlign = ContentAlignment.MiddleLeft;
                contextMenuStrip1.Items[0].ImageScaling = ToolStripItemImageScaling.SizeToFit;
                //contextMenuStrip1.Items[0].Click += delegate
                contextMenuStrip1.Items[0].Click += (s, e) =>
                {//反射AddEventHandler
                    添加目录ToolStripMenuItem_Click(s,e);
                };
                contextMenuStrip1.Items.Add("添加数据");
                contextMenuStrip1.Items[1].Image = UserResource.file;
                contextMenuStrip1.Items[1].TextAlign = ContentAlignment.MiddleRight;
                contextMenuStrip1.Items[1].DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                contextMenuStrip1.Items[1].ImageAlign = ContentAlignment.MiddleLeft;
                contextMenuStrip1.Items[1].ImageScaling = ToolStripItemImageScaling.SizeToFit;
                contextMenuStrip1.Items[1].Click += (s, e) =>
                {//反射AddEventHandler
                    toolStripButton1_Click(s,e);
                };
                contextMenuStrip1.Items.Add("目录改名");
                contextMenuStrip1.Items[2].Image = UserResource.folder;
                contextMenuStrip1.Items[2].TextAlign = ContentAlignment.MiddleRight;
                contextMenuStrip1.Items[2].DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                contextMenuStrip1.Items[2].ImageAlign = ContentAlignment.MiddleLeft;
                contextMenuStrip1.Items[2].ImageScaling = ToolStripItemImageScaling.SizeToFit;
                contextMenuStrip1.Items[2].Click += (s, e) =>
                {//反射AddEventHandler
                    目录改名ToolStripMenuItem_Click(s,e);
                };
                contextMenuStrip1.Items.Add("删除目录");
                contextMenuStrip1.Items[3].Image = UserResource.folder;
                contextMenuStrip1.Items[3].TextAlign = ContentAlignment.MiddleRight;
                contextMenuStrip1.Items[3].DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                contextMenuStrip1.Items[3].ImageAlign = ContentAlignment.MiddleLeft;
                contextMenuStrip1.Items[3].ImageScaling = ToolStripItemImageScaling.SizeToFit;
                contextMenuStrip1.Items[3].Click += (s,e)=>
                {//反射AddEventHandler
                    删除目录ToolStripMenuItem_Click(s,e);
                };
                contextMenuStrip1.Items.Add("上移");
                contextMenuStrip1.Items.Add("下移");

                //鼠标选中点击右键事件 并绑定右键菜单
                treeView_menuList.MouseDown += (s, e) => {
                    if (e.Button == MouseButtons.Right)
                    {//判断你点的是不是右键
                        Point ClickPoint = new Point(e.X, e.Y);
                        TreeNode CurrentNode = treeView_menuList.GetNodeAt(ClickPoint);
                        if (CurrentNode != null)
                        {//判断你点的是不是一个节点
                            treeView_menuList.SelectedNode = CurrentNode;//选中这个节点
                            if (!"1".Equals(CurrentNode.Name))
                            {//排除根节点
                                CurrentNode.ContextMenuStrip = contextMenuStrip1;
                                if ("2".Equals(CurrentNode.Name) ||
                                "8".Equals(CurrentNode.Name) ||
                                "15".Equals(CurrentNode.Name))
                                {
                                    //contextMenuStrip1.Items[0].Enabled = false;
                                    contextMenuStrip1.Items[2].Enabled = false;
                                    contextMenuStrip1.Items[3].Enabled = false;
                                    //reeview生成以后就支持单击节点修改。
                                    //如果不想左键修改，可在treeView1_MouseDown中设置treeView.LabelEdit = false;
                                    treeView_menuList.LabelEdit = false;
                                }
                                else
                                {
                                    //contextMenuStrip1.Items[0].Enabled = true;
                                    contextMenuStrip1.Items[2].Enabled = true;
                                    contextMenuStrip1.Items[3].Enabled = true;
                                    //reeview生成以后就支持单击节点修改。
                                    //如果不想左键修改，可在treeView1_MouseDown中设置treeView.LabelEdit = false;
                                    treeView_menuList.LabelEdit = true;
                                }

                            }
                            else
                            {
                                //reeview生成以后就支持单击节点修改。
                                //如果不想左键修改，可在treeView1_MouseDown中设置treeView.LabelEdit = false;
                                treeView_menuList.LabelEdit = false;
                            }
                        }
                    }
                };

                //鼠标选中点击事件,查看节点下的所以数据
                treeView_menuList.NodeMouseClick += (s, e) => {

                    ListViewHelper.setListView("listView_entryData", this).listViewData(e.Node.Name);
                };

                //设置treeView的图片集
                ImageList imageList = new ImageList();
                imageList.Images.Add(UserResource.folder);
                treeView_menuList.ImageList = imageList;

                //treeView.ImageIndex = 0;

                //treeView.ImageIndex = 0;
                //int a = treeView.SelectedImageIndex;

                //C#中Treeview判断选择的节点并执行不同的方法
                //treeView.AfterSelect += (s, e) =>
                //{
                //    if (e.Action == TreeViewAction.ByMouse)
                //    {
                //        if (e.Node.Nodes.Count == 0)
                //        {//说明当前选中节点没有子节点
                //        }
                //        else
                //        {
                //            if (e.Node.Name == "0")
                //            {
                //                contextMenuStrip1.Items[0].Enabled = true;
                //            }
                //            else if (e.Node.Name == "bbb")
                //            {
                //                //执行相应的方法（）；
                //            }
                //        }

                //    }
                //};

                TreeViewHelper.setTreeView("treeView_menuList", this).ModifyTreeView();
            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// 创建ListViewRightMenu菜单
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="treeView"></param>
        /// <param name="form"></param>
        public void createListViewRightMenu(ListView listView_entryData, TreeView treeView_menuList, Form form)
        {
            try
            {
                MiniPasswordBoxForm miniPasswordBoxForm = (MiniPasswordBoxForm)form;

                //右键菜单
                ContextMenuStrip contextMenuStrip1 = new ContextMenuStrip();
                //contextMenuStrip1.Items.Clear();
                contextMenuStrip1.Items.Add("详细资料");
                //contextMenuStrip1.Items[0].Click += new EventHandler(viewDetails);//详细资料点击事件
                contextMenuStrip1.Items[0].Click += (s, e) =>
                {
                    toolStripButton3_Click(s,e);
                };

                contextMenuStrip1.Items.Add("复制密码");
                contextMenuStrip1.Items[1].Click += (s, e) =>
                {
                    string id = listView_entryData.SelectedItems[0].Text;
                    string text = listView_entryData.SelectedItems[0].SubItems[3].Text;
                    string name = listView_entryData.SelectedItems[0].SubItems[3].Name;
                    //复制
                    if (name != "")
                        Clipboard.SetDataObject(name);

                    //粘贴
                    //IDataObject iData = Clipboard.GetDataObject();
                    //if (iData.GetDataPresent(DataFormats.Text))
                    //{
                    //    name = (String)iData.GetData(DataFormats.Text);
                    //}
                };
                //contextMenuStrip1.Items.Add("复制密码", null, new EventHandler(copyPassword));
                contextMenuStrip1.Items.Add("删除数据");
                contextMenuStrip1.Items[2].Click += (s, e) =>
                {//反射AddEventHandler
                    toolStripButton2_Click(s, e);
                };
                contextMenuStrip1.Items.Add("排序");
                ((ToolStripDropDownItem)contextMenuStrip1.Items[3]).DropDownItems.Add("按缺省方式排序");
                ((ToolStripDropDownItem)contextMenuStrip1.Items[3]).DropDownItems.Add("按标题方式排序");
                ((ToolStripDropDownItem)contextMenuStrip1.Items[3]).DropDownItems.Add("按用户名方式排序");
                ((ToolStripDropDownItem)contextMenuStrip1.Items[3]).DropDownItems.Add("按密码方式排序");
                contextMenuStrip1.Items.Add("移动");
                ((ToolStripDropDownItem)contextMenuStrip1.Items[4]).DropDownItems.Add("上移");
                ((ToolStripDropDownItem)contextMenuStrip1.Items[4]).DropDownItems.Add("下移");

                //是否开启右键菜单
                bool isRightMenu = false;

                //listview获得选中行
                listView_entryData.ItemSelectionChanged += (s, e) =>
                {
                    if (e.IsSelected)
                    {
                        if (listView_entryData.SelectedItems.Count == 0)
                        {
                            isRightMenu = false;
                            listView_entryData.ContextMenuStrip = null;
                            return;
                        }
                        isRightMenu = true;

                        //选中点击那一行的第一列的值，索引值必须是0，而且无论点这一行的第几列，选中的都是这一行第一列的值 ，如果想获取这一行除第一列外的值，则用subitems获取，[]中为索引，从1开始。
                        string site = listView_entryData.SelectedItems[0].Text;
                        string type = listView_entryData.SelectedItems[0].SubItems[1].Text;
                    }
                    else
                    {
                        isRightMenu = false;
                        listView_entryData.ContextMenuStrip = null;
                    }
                };

                //鼠标选中点击右键事件 并绑定右键菜单
                listView_entryData.MouseDown += (s, e) =>
                {
                    if (e.Button == MouseButtons.Right && isRightMenu == true)//判断你点的是不是右键
                    {
                        listView_entryData.ContextMenuStrip = contextMenuStrip1;
                    }
                };

                //在双击控件时发生
                listView_entryData.DoubleClick += (s, e) =>
                {
                    toolStripButton3_Click(s,e);
                };

                //获取用户当前选择的行的数据
                //string name = listView.FocusedItem.SubItems[0].Text;
                //name += "             ";
                //name += listView.FocusedItem.SubItems[1].Text;
                //MessageBox.Show(name);

                createListHeader(listView_entryData);
            }
            catch (Exception ex)
            {


            }
        }

        /// <summary>
        /// 列表头创建（记得，需要先创建列表头）
        /// </summary>
        public static void createListHeader(ListView listView)
        {
            try
            {
                int width = listView.Width / 3;
                ColumnHeader ch_1 = new ColumnHeader();
                ch_1.Text = "id";   //设置列标题
                ch_1.Width = 0;    //设置列宽度
                ch_1.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
                listView.Columns.Add(ch_1);    //将列头添加到ListView控件。
                ColumnHeader ch_2 = new ColumnHeader();
                ch_2.Text = "标题";   //设置列标题
                ch_2.Width = width;    //设置列宽度
                ch_2.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
                listView.Columns.Add(ch_2);    //将列头添加到ListView控件。
                ColumnHeader ch_3 = new ColumnHeader();
                ch_3.Text = "用户名";   //设置列标题
                ch_3.Width = width;    //设置列宽度
                ch_3.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
                listView.Columns.Add(ch_3);    //将列头添加到ListView控件。
                ColumnHeader ch_4 = new ColumnHeader();
                ch_4.Text = "密码";   //设置列标题
                ch_4.Width = width;    //设置列宽度
                ch_4.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
                listView.Columns.Add(ch_4);    //将列头添加到ListView控件。

                //listView.ItemSelectionChanged 
                listView.GridLines = true;//设置行和列之间是否显示网格线。（默认为false）提示：只有在Details视图该属性才有意义。
                listView.FullRowSelect = true; //设置是否行选择模式。(默认为false)提示：只有在Details视图该属性才有意义。
            }
            catch (Exception ex)
            {


            }
        }

        /// <summary>
        /// 最小化到任务栏后的右键菜单
        /// </summary>
        private void Initializenotifyicon()
        {
            //定义一个MenuItem数组，并把此数组同时赋值给ContextMenu对象 
            MenuItem[] mnuItms = new MenuItem[3];
            mnuItms[0] = new MenuItem();
            mnuItms[0].Text = "显示窗口";
            mnuItms[0].Click += new System.EventHandler(this.notifyIcon1_showfrom);

            mnuItms[1] = new MenuItem("-");

            mnuItms[2] = new MenuItem();
            mnuItms[2].Text = "退出系统";
            mnuItms[2].Click += new System.EventHandler(this.ExitSelect);
            mnuItms[2].DefaultItem = true;

            notifyiconMnu = new ContextMenu(mnuItms);
            this.notifyIcon1.ContextMenu = notifyiconMnu;
            //为托盘程序加入设定好的ContextMenu对象 
        }

        /// <summary>
        /// 显示窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void notifyIcon1_showfrom(object sender, System.EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.Show();
                this.WindowState = FormWindowState.Normal;//还原窗体显示
                this.Activate();//激活窗体并给予它焦点 
                this.ShowInTaskbar = true;//任务栏区显示图标
                this.notifyIcon1.Visible = false;//托盘区图标隐藏 
            }
        }

        /// <summary>
        /// 退出系统
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ExitSelect(object sender, System.EventArgs e)
        {
            //隐藏托盘程序中的图标 
            this.notifyIcon1.Visible = false;
            //关闭系统 
            this.Close();
            this.Dispose(true);
        }

        private void 新建密码箱ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreatePasswordBoxForm form = new CreatePasswordBoxForm();
            form.ShowDialog();
        }

        private void 打开密码箱ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            LandingForm form = new LandingForm();
            form.ShowDialog();

        }

        private void 添加目录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addDirectory();
        }

        /// <summary>
        /// 添加列表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            uniformlyOpenAddOrModify(this.listView_entryData, true);
        }

        private void 优化文件大小ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MySQLiteHelper.ExecuteZip();
        }

        private void 更改登陆密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 目录改名ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            modifyDirectory(this.treeView_menuList);
        }

        private void 删除目录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            deleteDirectory();
        }

        private void 添加条目ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.toolStripButton1_Click(sender, e);
        }

        /// <summary>
        /// 删除列表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 删除条目ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripButton2_Click(sender, e);
        }

        private void 消息资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 搜索工具栏ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 程序锁定ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 窗口置顶ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!this.TopMost)
            {
                this.toolStripButton5.Text = "取消置顶";
                this.TopMost = true;
            }
            else
            {
                this.toolStripButton5.Text = "窗口置顶";
                this.TopMost = false;
            }
        }

        private void 选项ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OptionTabForm form = new OptionTabForm();
            form.ShowDialog(this);
        }

        private void 软件说明ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 使用须知ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 访问首页ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                //方法一：从注册表中读取默认浏览器可执行文件路径
                //RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
                //string s = key.GetValue("").ToString();
                //s就是你的默认浏览器，不过后面带了参数，把它截去，不过需要注意的是：不同的浏览器后面的参数不一样！  
                //"D:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"  
                //System.Diagnostics.Process.Start(s.Substring(0, s.Length - 8), "http://www.jlynet.cn");

                //方法二：调用系统默认的浏览器   
                //System.Diagnostics.Process.Start("explorer.exe", "http://www.jlynet.cn");

                //方法三：调用系统默认的浏览器   
                System.Diagnostics.Process.Start("http://www.jlynet.cn");

                //方法四：调用IE浏览器    
                //System.Diagnostics.Process.Start("iexplore.exe", "http://www.jlynet.cn");
            }
            catch (Exception ex) { }
        }

        private void 联系作者ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //System.Text.Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
            //发送地址 
            string to = "jly@jlynet.cn";
            //主题 
            string subject = "爱上猫的小鱼儿，您好";
            //subject = System.Web.HttpUtility.UrlEncode(subject, enc);
            //内容
            string body = "密码箱软件使用反馈：\r\n";
            // body = System.Web.HttpUtility.UrlEncode(body, enc);//
            //string cc = ""; 
            //string bcc = "";
            //打开标准的软件客户端
            //System.Diagnostics.Process.Start(string.Format("mailto:{0}?subject={1}&body={2}&cc={3}&bcc={4}", to, subject, body, cc, bcc));
            System.Diagnostics.Process.Start(string.Format("mailto:{0}?subject={1}&body={2}", to, subject, body));
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox_My form = new AboutBox_My();
            form.ShowDialog();
        }

        private void 添加条目ToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void 目录改名ToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void 删除目录ToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void 上移ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 下移ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 详细资料ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 复制密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 添加条目ToolStripMenuItem2_Click(object sender, EventArgs e)
        {

        }

        private void 删除条目ToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void 按缺省方式排序ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 按标题方式排序ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 按用户名方式排序ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 按密码方式排序ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 上移ToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void 下移ToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        //搜索
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            //string search = this.toolStripTextBox_search.Text;
            //if (!StringHelper.IsNullOrEmpty(search))
            //{
            //    ListViewHelper.listViewDataSearch(this.listView_entryData, search);
            //}
            //SearchForm a = new SearchForm();
            //this.AddOwnedForm(a);
            //ListView l2 = new ListView();
            //l2.AutoSize = true;
            //l2.Height = 21;
            //l2.Width = 150;
            //l2.Visible = true;
            //l2.Location = new System.Drawing.Point(121, 92);
            //this.Controls.Add(l2);

            // listView1
            //l2.Location = new System.Drawing.Point(12, 454);
            //l2.Name = "listView1";
            //l2.Size = new System.Drawing.Size(704, 168);
            //l2.TabIndex = 4;
            //l2.UseCompatibleStateImageBehavior = false;
            //this.Controls.Add(l2);

            //this.ResumeLayout(false);
            //this.PerformLayout();



        }

        /// <summary>
        /// 删除列表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            deleteDetails(this.listView_entryData);
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            uniformlyOpenAddOrModify(this.listView_entryData, false);
        }

        public string lockpwd = "0";
        void 锁定操作()
        {
            //lockpwd = Microsoft.VisualBasic.Interaction.InputBox("锁定密码", "锁定窗口", "123", 100, 100);
            this.Enabled = false;
        }
        void 解锁()
        {
            if (lockpwd != "0")
            {
                //String unlock = Microsoft.VisualBasic.Interaction.InputBox("解锁密码", "解锁", "请输入解锁密码", 100, 100);
                if ("" == lockpwd)

                {
                    this.Enabled = true;
                    lockpwd = "0";

                }
                else
                {
                    MessageBox.Show("密码错误，重启程序需要重新登录验证！");
                }
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {

        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            if (!this.TopMost)
            {
                this.toolStripButton5.Text = "取消置顶";
                this.TopMost = true;
            }
            else
            {
                this.toolStripButton5.Text = "窗口置顶";
                this.TopMost = false;
            }
        }

        private void toolStripButton2_Click_1(object sender, EventArgs e)
        {
            //点击注销按钮事件里面写：
            if (MessageBox.Show("您确定要注销登录吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
                //Application.ExitThread();
                System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
            }
        }

        private void 详细资料ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            this.toolStripButton3_Click(sender, e);
        }

        /// <summary>
        /// 添加修改
        /// </summary>
        public void addDirectory()
        {
            DirectoryDataTableModel model = new DirectoryDataTableModel();
            model = TreeViewHelper.setTreeView("treeView_menuList",this).GetSelectedNode();
            string directory_id = model.id;
            if (!"1".Equals(directory_id))
            {
                AddDirectoryForm addDirectoryForm = new AddDirectoryForm(model);
                Dictionary<string, object> dic = new Dictionary<string, object>();
                addDirectoryForm.FormClosed += (s, ex) =>
                {
                    TreeViewHelper.setTreeView("treeView_menuList", this).AddTreeView(Convert.ToInt32(directory_id), treeView_menuList.SelectedNode);
                };
                addDirectoryForm.ShowDialog(this);
            }
        }

        /// <summary>
        /// 修改目录
        /// </summary>
        public void modifyDirectory(TreeView treeView_menuList)
        {
            DirectoryDataTableModel model = new DirectoryDataTableModel();
            model = TreeViewHelper.setTreeView("treeView_menuList", this).GetSelectedNode();
            string directory_id = model.id;
            if (!"1".Equals(directory_id) &&
                !"2".Equals(directory_id) &&
                !"8".Equals(directory_id) &&
                !"15".Equals(directory_id))
            {
                treeView_menuList.LabelEdit = true;
                treeView_menuList.SelectedNode.BeginEdit();
            }
            else
            {
                treeView_menuList.LabelEdit = false;
            }
        }

        public void deleteDirectory()
        {
            DirectoryDataTableModel model = new DirectoryDataTableModel();
            model = TreeViewHelper.setTreeView("treeView_menuList", this).GetSelectedNode();
            string directory_id = model.id;
            if (!"1".Equals(directory_id) &&
                !"2".Equals(directory_id) &&
                !"8".Equals(directory_id) &&
                !"15".Equals(directory_id))
            {
                TreeViewHelper.setTreeView("treeView_menuList", this).RemoveTreeView();
            }
        }

        /// <summary>
        /// 删除列表数据
        /// </summary>
        public void deleteDetails(ListView listView_entryData)
        {
            if (!(listView_entryData.SelectedItems.Count == 0))
            {
                DirectoryDataTableModel model = new DirectoryDataTableModel();
                model = TreeViewHelper.setTreeView("treeView_menuList", this).GetSelectedNode();
                model.entryDataTableModel.id= listView_entryData.SelectedItems[0].Text;
                string id = model.entryDataTableModel.id;
                string directory_id = model.id;
                //string type = listView.SelectedItems[0].SubItems[1].Text;
                ListViewHelper.setListView("listView_entryData", this).deleteListView(id, directory_id);
            }
        }

        /// <summary>
        /// 统一打开与修改
        /// </summary>
        /// <param name="treeView_menuList"></param>
        /// <param name="listView_entryData"></param>
        /// <param name="isAdd"></param>
        public void uniformlyOpenAddOrModify(ListView listView_entryData, bool isAdd)
        {
            DirectoryDataTableModel model = new DirectoryDataTableModel();
            model = TreeViewHelper.setTreeView("treeView_menuList", this).GetSelectedNode();
            if (!isAdd && listView_entryData.SelectedItems != null && listView_entryData.SelectedItems.Count > 0)
            {
                model.isEdit = true;
                model.entryDataTableModel.id = listView_entryData.SelectedItems[0].Text;
            }
            else
            {
                model.isEdit = false;
            }
                
            if (!("1".Equals(model.id)))
            {//不属于顶级节点
                if ("1".Equals(model.type))
                {
                    AddEntryForm addEntryForm = new AddEntryForm(model);
                    addEntryForm.FormClosed += (s, ex) =>
                    {
                        ListViewHelper.setListView("listView_entryData", this).listViewData(model.id);
                    };
                    addEntryForm.ShowDialog();
                }
                else if ("2".Equals(model.type))
                {
                    AddEntryForm2 addEntryForm = new AddEntryForm2(model);
                    addEntryForm.FormClosed += (s, ex) =>
                    {
                        ListViewHelper.setListView("listView_entryData", this).listViewData(model.id);
                    };
                    addEntryForm.ShowDialog();
                }
                else if ("3".Equals(model.type))
                {
                    AddEntryForm3 addEntryForm = new AddEntryForm3(model);
                    addEntryForm.FormClosed += (s, ex) =>
                    {
                        ListViewHelper.setListView("listView_entryData", this).listViewData(model.id);
                    };
                    addEntryForm.ShowDialog();
                }
                else
                {
                    MessageBox.Show("类型错误，打开窗口错误！");
                    return;
                }
            }
        }
    }
}
